using UnityEngine;

public class MeteorScript : MonoBehaviour
{
	public static MeteorScript Instance;

	public Transform[] pointSpawn;

	public GameObject meteo;

	public int number;

	private GameObject[] metes;

	private float timer;

	public float secondsDrop;

	private Transform target;

	private void Start()
	{
		Instance = this;
		_Start();
	}

	public void RemoveMetes()
	{
		GameObject[] array = metes;
		foreach (GameObject gameObject in array)
		{
			if (gameObject != null)
			{
				UnityEngine.Object.Destroy(gameObject);
			}
		}
	}

	public void _Start()
	{
		target = Camera.main.transform;
		metes = new GameObject[number];
		for (int i = 0; i < number; i++)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate(meteo);
			metes[i] = gameObject;
			metes[i].SetActive(value: false);
		}
	}

	private void Update()
	{
		if (BadLogic.playing)
		{
			timer += Time.deltaTime;
			if (timer >= secondsDrop)
			{
				timer = 0f;
				_DropMeteo();
			}
		}
	}

	private void _DropMeteo()
	{
		int num = UnityEngine.Random.Range(0, pointSpawn.Length);
		GameObject[] array = metes;
		int num2 = 0;
		GameObject gameObject;
		while (true)
		{
			if (num2 < array.Length)
			{
				gameObject = array[num2];
				if (gameObject != null && !gameObject.activeInHierarchy)
				{
					break;
				}
				num2++;
				continue;
			}
			return;
		}
		gameObject.transform.position = pointSpawn[num].position;
		gameObject.SetActive(value: true);
	}
}
